package mapReduce.homework.q6_orderInfoTop10;

import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableComparator;

public class GetMenuSailCountGroupComparator extends WritableComparator {
    public GetMenuSailCountGroupComparator(){
        super(OrderInfoWritable.class,true);
    }
    @Override
    public int compare(WritableComparable a, WritableComparable b) {
        int res = 0;

        OrderInfoWritable aBean = (OrderInfoWritable)a;
        OrderInfoWritable bBean = (OrderInfoWritable)b;

        /*
            按年份和合作方的订单名称分组
         */
        if(aBean.getYear().equals(bBean.getYear())){
            if(aBean.getmenuId().equals(bBean.getmenuId())){
                res = aBean.getPartner().compareTo(bBean.getPartner());
            }else{
                res = aBean.getmenuId().compareTo(bBean.getmenuId());
            }
        }else{
            res = aBean.getYear().compareTo(bBean.getYear());
        }
        return res;
    }
}
